#include "loading.h"
#include "ui_loading.h"

Loading::Loading(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Loading)
{
    ui->setupUi(this);
}

Loading::~Loading()
{
    delete ui;
}

void Loading::Sleep(int msec)
{
    QTime dieTime = QTime::currentTime().addMSecs(msec);
    while( QTime::currentTime() < dieTime ){
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }
}

void Loading::Show_and_close() {
    this->show();
    QString num[4] = {"0%", "30%", "80%", "100%"};
    QString t[4] = {"data loading", "data loading..", "data loading....", "data loading......"};
    for (int i = 0; i < 4; i++) {
        ui->loadingnum->setText(num[i]);
        ui->text->setText(t[i]);
        Sleep(700);
    }
    this->close();
}

void Loading::closeEvent(QCloseEvent *)
{
    emit clo();
}
